<template>
  <div>
    <div id="main" style="width: 800px;height:400px;"></div>
  </div>
</template>
<style lang="less" scoped>
  #ad {
    background-color: #007af5;
  }

</style>
<script>
  import * as echarts from "echarts"
  import _ from "lodash";
  export default {
    data() {
      return {
        data: {}
      }
    },
    methods: {
      //   async getData() {
      //   }
    },
    async mounted() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById('main'));

      // 使用刚指定的配置项和数据显示图表。
      const {
        data: response
      } = await this.$http.get('reports/type/1');
      if (response.meta.status == 200) {
        this.data = response.data;
        console.log(this.data);
      } else {
        this.$message.error(response.meta.msg);
      }
      const options = {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#007af5'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [{
          boundaryGap: false
        }],
        yAxis: [{
          type: 'value'
        }]
      }
      this.data = _.merge(options, this.data);
      myChart.setOption(this.data);
    }
  }

</script>
